#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
typedef long long ll;
template<typename T> 
inline void read(T &x){
	x=0;T f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

struct node{
  int val,ch,xd;
}no[100005];

int fa[100005];
bool del[100005];
int n,m;
//find dad
int find(int x){
  if(fa[x]==x)return x;
  return fa[x]=find(fa[x]);
}
// merge too tree
int merge(int x,int y){
  if(!x||!y)return x|y;
  if(no[x].val>no[y].val||
     (no[x].val==no[y].val&&y<x))swap(x,y);
  no[y].xd=no[x].ch;
  no[x].ch=y;
  return x;
}
//merge all bros
int ms(int x){
  if(!x||!no[x].xd)return x;
  int a=no[x].xd,b=no[a].xd;
  no[x].xd=no[a].xd=0;
  return merge(merge(x,a),ms(b));
}
int main(){
    #ifdef BUG
    freopen("a.in","r",stdin);
    #endif
    read(n);read(m);
    memset(no,0,sizeof no);
    memset(del,0,sizeof del);
    for(int i=1;i<=n;i++){
      fa[i]=i;
      read(no[i].val);
    }
    int t,a,b,x,y;
    while(m--){
      read(t);
      if(t==2){
	read(a);
	if(del[a]){
	  printf("-1\n");
	  continue;
	}
	a=find(a);
	printf("%d\n",no[a].val);
	del[a]=1;
	fa[a]=ms(no[a].ch);
	fa[fa[a]]=fa[a];
	//for(int i=1;i<=n;i++)cout<<i<<';'<<fa[i]<<' ';cout<<endl;
      }else{
	read(a);read(b);
	if(del[a]||del[b])continue;
	x=find(a);y=find(b);
	if(x==y)continue;
	fa[x]=fa[y]=merge(x,y);
      }
      //for(int i=1;i<=n;i++)cout<<i<<':'<<find(i)<<' ';cout<<endl;
    }
}
